<template>
<el-container>
  <el-header style="background-color: white; color: black;">
      <h1 align="center">库存列表</h1>
  </el-header>
  <el-main>
    <!-- 查询条件表单 -->
    <el-form :inline="true" :model="queryForm" class="demo-form-inline">
      <el-form-item label="商品名字">
        <el-input v-model="queryForm.goodsName" placeholder="商品名字"></el-input>
      </el-form-item>
      <el-form-item label="商品类型">
        <el-input v-model="queryForm.goodsType" placeholder="商品类型"></el-input>
      </el-form-item>
      <el-form-item label="入库人">
        <el-input v-model="queryForm.goodsUserName" placeholder="入库人"></el-input>
      </el-form-item>
      <el-form-item label="供货人">
        <el-input v-model="queryForm.goodsSuppliersName" placeholder="供货人"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="loadData()">查询</el-button>
        <!-- <el-button type="primary" @click="exportExcel()">导出所有数据</el-button> -->

      </el-form-item>
    </el-form>
    <download-excel
             class="export-excel-wrapper"
             :data="tableAllData"
             :fields="fieldLabels"
             :header="fileName"
             name="仓库数据.xls"
           >
             <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
      <el-button type="success" @click="exportExcel">导出</el-button>
    </download-excel>
    <el-table :data="tableData" style="100%" >
      <!-- 列组件 -->
      <!-- prop 对应当前页集合的对象属性-->
      <el-table-column prop="goodsId" label="编号" style="0%"></el-table-column>
      <el-table-column prop="goodsName" label="商品名字" style="0%"></el-table-column>
      <el-table-column prop="goodsType" label="商品类型" style="0%"></el-table-column>
      <el-table-column prop="goodsPrice" label="商品价格" style="0%"></el-table-column>
      <el-table-column prop="goodsNums" label="商品数量" style="0%"></el-table-column>
      <el-table-column prop="goodsJoinTime" label="商品加入时间" style="0%"></el-table-column>
      <el-table-column prop="goodsUserName" label="入库人" style="0%"></el-table-column>
      <el-table-column prop="goodsSuppliersName" label="供货人" style="0%"></el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
    @size-change="select"
    @current-change="selectPage"
    :current-page="queryForm.page"
    :page-sizes="[10,15,20]"
    :page-size="queryForm.row"
    :total="total"
    layout="total,sizes,prev,pager,next,jumper"
    >

    </el-pagination>
  </el-main>
</el-container>
</template>

<script>
  export default {
      data() {
        return {
          tableData: [],
          totalPage: 0, //总页数
          total: 0, //总条数
          tableAllData: [],
          fieldLabels:{
            '编号':'goodsId',
            '商品名字':'goodsName',
            '商品类型':'goodsType',
            '商品价格':'goodsPrice',
            '商品数量':'goodsNums',
            '商品加入时间':'goodsJoinTime',
            '入库人':'goodsUserName',
            '供货人':'goodsSuppliersName'
            },
          fileName :"仓库数据",
          queryForm: {
            page: 1,
            row: 10,
            goodsName:"",
            goodsType:"",
            goodsUserName:"",
            goodsSuppliersName:"",
          },
        }
      },
      methods: {
        loadData() { //加载数据
          var self = this;
          var http = this.$http.post("/api/goods/inventoryIndex",this.$qs.stringify(this.queryForm));
          http.then(function(rs) {
            if (rs.data.code == 200) {
              self.tableData = rs.data.data.data;
              self.total = rs.data.data.total;
              self.totalPage = rs.data.data.totalPage;
            }else{
              self.tableData=[];
              self.total=0;
            }
          })
        },
        select(row){ //分页下拉框选中触发的事件，row是当前选中条数
          this.queryForm.row=row;
          //刷新
          this.loadData();
        },
        selectPage(page){//选中页码触发的事件, page就是选中的页码
          this.queryForm.page = page;
          //刷新
          this.loadData();
        },
        exportExcel() {
          var self = this;
          var http = this.$http.post("/api/goods/selectInventory");
          http.then(function(rs) {
            if (rs.data.code == 200) {
              self.tableAllData = rs.data.data
            }
          })
        },
      },
      mounted(){
        this.loadData();
      }
    }
</script>

<style>
  .el-table .warning-row {
      background: oldlace;
    }

    .el-table .success-row {
      background: #f0f9eb;
    }
</style>
